import requests
import time
import json
from selenium import webdriver
# 导入Select类
from selenium.webdriver.support.ui import Select


# 创建Select对象

wd = webdriver.Chrome(r'C:\Users\humeiersi777\Downloads\chromedriver_win32\chromedriver.exe')
wd.implicitly_wait(10)
wd.get('https://id.sspu.edu.cn/cas/login')
username=wd.find_element_by_id('username')
password=wd.find_element_by_id('password')
btn=wd.find_element_by_css_selector('.submit_button')
username.send_keys('你的账号')
password.send_keys('你的密码')
btn.click()
time.sleep(1)
cookies=wd.get_cookies()
f1=open('cookie.txt','w')
f1.write(json.dumps(cookies))
f1.close()
a=wd.find_element_by_tag_name('a')
a.click()
for handle in wd.window_handles:
    # 先切换到该窗口
    wd.switch_to.window(handle)
    # 得到该窗口的标题栏字符串，判断是不是我们要操作的那个窗口
    if 'Bing' in wd.title:
        # 如果是，那么这时候WebDriver对象就是对应的该该窗口，正好，跳出循环，
        break
fre=wd.find_element_by_css_selector('.freqUse')
fre.click()
time.sleep(1)
new=wd.find_element_by_css_selector('span[title="新建流程"]')
new.click()
time.sleep(1)
wd.switch_to.frame('mainFrame')
btn=wd.find_element_by_css_selector('#tab_1 a')
btn.click()
wd.switch_to.frame('tabcontentframe')
mainWindow = wd.current_window_handle
chuxiaola=wd.find_element_by_xpath('/html/body/table[2]/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr[1]/td[1]/div[2]/div[2]/div[9]/div[1]/a')
chuxiaola.click()
for handle in wd.window_handles:
    # 先切换到该窗口
    wd.switch_to.window(handle)
    # 得到该窗口的标题栏字符串，判断是不是我们要操作的那个窗口
    if 'Bing' in wd.title:
        # 如果是，那么这时候WebDriver对象就是对应的该该窗口，正好，跳出循环，
        break
wd.switch_to.frame('bodyiframe')
# thing=wd.find_element_by_css_selector('#field11683_tdwrap div textarea')
#具体事由：.
thing=wd.find_element_by_id('field11241')
thing.send_keys('.')
select = Select(wd.find_element_by_id("field11404"))
select.select_by_visible_text("本专科生")
select2 = Select(wd.find_element_by_id("field12523"))
select2.select_by_visible_text("否")
select3 = Select(wd.find_element_by_id("field11663"))
select3.select_by_visible_text("外出实习")
select4 = Select(wd.find_element_by_id("field11251"))
select4.select_by_visible_text("12:00-00:00")
btn2=wd.find_element_by_id('field11304_browserbtn')
btn2.click()
select5 = Select(wd.find_element_by_id("field11255"))
select5.select_by_visible_text("12:00-00:00")
time.sleep(1)

wd.switch_to.default_content()
wd.switch_to.frame(wd.find_element_by_css_selector('div div iframe:nth-child(2)'))
wd.switch_to.frame('main')
way=wd.find_element_by_xpath('//*[@id="e8_src_table"]/tbody/tr[4]')
way.click()
img=wd.find_element_by_id('singleArrowTo')
img.click()
for_sure=wd.find_element_by_xpath('//*[@id="btnok"]')
for_sure.click()
wd.switch_to.default_content()
wd.switch_to.frame('bodyiframe')
select2 = Select(wd.find_element_by_id("field12523"))
select2.select_by_visible_text("是")
select2 = Select(wd.find_element_by_id("field12523"))
select2.select_by_visible_text("否")
date=wd.find_element_by_id('field11250browser')
date.click()
time.sleep(1)
wd.switch_to.frame(wd.find_element_by_xpath('//*[@id="_my97DP"]/iframe'))
today=wd.find_element_by_id('dpTodayInput')
today.click()
# 返校日期
wd.switch_to.default_content()
wd.switch_to.frame('bodyiframe')
date=wd.find_element_by_id('field13063browser')
date.click()
time.sleep(1)
wd.switch_to.frame(wd.find_element_by_xpath('//*[@id="_my97DP"]/iframe'))
today=wd.find_element_by_id('dpTodayInput')
today.click()
time.sleep(1)
wd.switch_to.default_content()
wd.switch_to.frame('bodyiframe')
select7 = Select(wd.find_element_by_xpath('//*[@id="field11259"]'))
select7.select_by_visible_text("良好")
fin1=wd.find_element_by_xpath('//*[@id="flowbody"]/form/div[1]/table/tbody/tr/td/table/tbody/tr[21]/td/div/span[1]/span/span')
fin1.click()
fin2=wd.find_element_by_xpath('//*[@id="flowbody"]/form/div[1]/table/tbody/tr/td/table/tbody/tr[22]/td/div/span[1]/span/span')
fin2.click()
wd.switch_to.default_content()
sub=wd.find_element_by_css_selector('.e8_btn_top_first')
sub.click()



